/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>Project: app2022 - OutDemo
 * <p>Powered by webrx On 2022-01-06 19:52:03
 *
* @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class OutDemo {
    public static void main(String[] args) throws IOException {
//        System.out.println("hello");
//        System.out.println();
//        System.out.print("aa\n%n\r\n");
//        System.err.println("error....");
//
//        JOptionPane.showMessageDialog(null, "hello world 中文");


        //输出到文件中，覆盖方式
        PrintWriter out = new PrintWriter(new File("data\\user.txt"));
        out.printf("欢迎：%s!%n", "李四");
        out.flush();
        out.close();

        PrintWriter o = new PrintWriter(new FileWriter("data\\user2.txt", true));
        o.printf("欢迎：%s![注册时间：%2$tF %<tT]%n", "James Gosling", System.currentTimeMillis());
        o.flush();
        o.close();

        System.out.println(long2ip(978559132L));
    }

    public static long ip2long(String ip) {
        String[] ipArray = ip.split("\\.");
        List<Long> ipNums = new ArrayList<Long>();
        for (String n : ipArray) {
            ipNums.add(Long.valueOf(Long.parseLong(n.trim())));
        }
        long ZhongIPNumTotal = ipNums.get(0).longValue() * 256L * 256L * 256L + ipNums.get(1).longValue() * 256L * 256L + ipNums.get(2).longValue() * 256L + ipNums.get(3).longValue();
        return ZhongIPNumTotal;
    }

    public static String long2ip(long ipaddr) {
        long y = ipaddr % 256;
        long m = (ipaddr) / (256 * 256 * 256);
        long n = (ipaddr - 256 * 256 * 256 * m) / (256 * 256);
        long x = (ipaddr - 256 * 256 * 256 * m - 256 * 256 * n) / 256;
        return m + "." + n + "." + x + "." + y;
    }
}
